﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BulldogCMS.Core.Tests.Helper
{
    public class MemoryCache : BulldogCMS.Core.Storage.Cache.IStorageCache
    {
        private Dictionary<string, object> _cache = new Dictionary<string, object>();

        public Core.Storage.Node GetNode(string nodePath)
        {
            if (this._cache.ContainsKey(nodePath))
            {
                return this._cache[nodePath] as Core.Storage.Node;
            }
            else
            {
                return null;
            }
        }

        public void SetNode(Core.Storage.Node node)
        {
            this._cache[node.Path] = node;
        }

        public IEnumerable<Core.Storage.Node> GetSubNodes(string parentNodePath)
        {
            if (this._cache.ContainsKey(parentNodePath + "_childern"))
            {
                return this._cache[parentNodePath + "_childern"] as IEnumerable<Core.Storage.Node>;
            }
            else
            {
                return null;
            }            
        }

        public void RemoveNode(string nodePath)
        {
            if (this._cache.ContainsKey(nodePath))
            {
                this._cache.Remove(nodePath);
            }
        }

        public void RemoveSubNodes(string parentNodePath)
        {
            if (this._cache.ContainsKey(parentNodePath + "_childern"))
            {
                this._cache.Remove(parentNodePath + "_childern");
            }
        }

        public void SetSubNodes(string parentNodePath, IEnumerable<Core.Storage.Node> childNodes)
        {
            this._cache[parentNodePath + "_childern"] = childNodes;
        }


        public Core.Storage.NodeVersion GetNodeVersion(string nodePath, string language, int version)
        {
            throw new NotImplementedException();
        }

        public void SetNodeVersion(string nodePath, Core.Storage.NodeVersion nodeVersion)
        {
            throw new NotImplementedException();
        }
    }
}
